﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufWidgetAgentControl.h"
#include <QtCore/QPointer>

namespace gnuf {
    class Item;
    class QtWidgetAgent;
    class GNUF_BASE_EXPORT WidgetAgent final
        : public ItemWith<QtWidgetAgent>
        , public WidgetAgentControlAdpatation
    {
    public:
        static const EItemType Type;
        explicit WidgetAgent(Item *);
        virtual ~WidgetAgent();

        void setQtWidget(QWidget * qtWidget) { m_qtWidget = qtWidget; }
        QWidget * qtWidget() const { return m_qtWidget.data(); }
        QWidget * takeAwayQtWidget() const;

        void setTransferOwnership(bool val) { m_transferOwnership = val; }
        bool transferOwnership() const { return m_transferOwnership; }

    protected:
        // Inherits from ItemWith...
        virtual void onDisconnectFromMyQtItem() override;
        virtual void onTableRowSelectionChanged(bool) override;

        // Inherits from WidgetAgentControlAdaptation...
        virtual void onCollectLocation(std::set<const gcmp::UniqueString *> &) const override;

    private:
        mutable QPointer<QWidget> m_qtWidget;
        bool m_transferOwnership;
    };
}
